/**
 * 
 */
package net.mikoo.seals.boss.common.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang.StringUtils;

/**
 * @author huangxm
 * 
 */
public class DateUtil {
	
	
	
	public static String getCurrentStr(String fromate) {

		SimpleDateFormat sf = new SimpleDateFormat(fromate);
		return sf.format(new Date());
	}

	public static String addMinute(String date, int minute, String fromate) throws ParseException {

		SimpleDateFormat sf = new SimpleDateFormat(fromate);
		Date dates = sf.parse(date);

		Calendar nowTime = Calendar.getInstance();
		nowTime.setTime(dates);
		nowTime.add(Calendar.MINUTE, minute);

		return sf.format(nowTime.getTime());
	}

	/**
	 * 
	 * @return
	 */
	public static Date nextYear() {

		Calendar curr = Calendar.getInstance();
		curr.set(Calendar.YEAR, curr.get(Calendar.YEAR) + 1);
		Date date = curr.getTime();
		return date;
	}
	
	public static String formate(Date date,String formate){
		if(date == null){
			return "";
		}
		SimpleDateFormat sdf = new SimpleDateFormat(formate);
		return sdf.format(date);
	}
	
	public static Date stringToDate(String date,String formate){
		
		if(StringUtils.isBlank(date)){
			return null;
		}
		
		SimpleDateFormat sdf = new SimpleDateFormat(formate);
		Date d = null;
		try {
			d = sdf.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return d;
	}
	
	public static Date getCurretDate(){
		
		
		return new Date();
	}
	
	public static Date addMinute(Date date,int num){
		
		Calendar nowTime = Calendar.getInstance();
		nowTime.setTime(date);
		nowTime.add(Calendar.MINUTE, 5);
		return nowTime.getTime();
	}
	
	/**
	 * 
	 *	比较日期大小
	 *	date1 > date2  为1
	 *	date1 = date2  为0
	 *	date1 < date2  为-1
	 *
	 * @param date1
	 * @param date2
	 * @return
	 */
	public static int compare(Date date1, Date date2) {

		try {

			if (date1.getTime() > date2.getTime()) {
				return 1;
			} else if (date1.getTime() < date2.getTime()) {
				return -1;
			} else {
				return 0;
			}
		} catch (Exception exception) {
			exception.printStackTrace();
		}
		return 0;
	}

}
